package com.maikang.exammall.api;

import com.maikang.exammall.entity.dto.ResponseDTO;
import com.maikang.exammall.service.KefuService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;

@RestController
@RequiredArgsConstructor
@Log4j2
@RequestMapping("/api/kefu")
public class KefuController {
    final private KefuService service;

    @ApiOperation("获取客服id列表")
    @GetMapping(value = "/ids")
    public ResponseDTO<List<String>> findAll() {
        return ResponseDTO.ok(service.findAllKefuId());
    }

    @ApiOperation("随机获取一个在线客服id")
    @GetMapping(value = "/id")
    public ResponseDTO<String> findOne() {
        List<String> allKefuId = service.findAllKefuId();
        String kefu = null;
        Random random = new Random();
        int n = random.nextInt(allKefuId.size());
        kefu = allKefuId.get(n);
        return ResponseDTO.ok(kefu);
    }
}
